package br.com.sgi.bean;

import java.util.List;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Controller;

import br.com.sgi.model.Task;

@Controller("taskHome")
@Scope("request")
public class TaskHome {

	private static final Logger logger = LoggerFactory.getLogger(TaskHome.class);

	@Autowired
	private TaskService taskService;
	
	private Task task = new Task();
	private List<Task> tasks;

	
	public String getMessage() {
		logger.debug("Returning message from task home bean");
		return "Hello from Spring";
	}	

	public Task getTask() {
		return task;
	}

	public void saveTask() {
			taskService.save(task);
			task = new Task();
			invalidateTasks();
	}

	private void invalidateTasks() {
		tasks = null;
	}

	public List<Task> getTasks() {
		if (tasks == null) {
			tasks = taskService.buscarTasks();
		}
		return tasks;
		
	}

	
	
}
